#include<ctime>
#include "Date.h"

Date::Date() {

}
Date::Date(int minutes)
{
    // 获奖今天日期
    time_t now = time(NULL);
    struct tm t; 
    localtime_s( &t ,& now);
    this->year = t.tm_year + 1900;
    this->month = t.tm_mon + 1;
    this->day = t.tm_mday;
    // 设置时间点
    minutes += 8 * 60 + 30;
    this->hour = minutes / 60;
    this->minute = minutes % 60;
}
Date::Date(int inputYear, int inputMonth, int inputDay, int inputHour, int inputMinute) {
    this->year = inputDay;
    this->month = inputMonth;
    this->day = inputDay;
    this->hour = inputHour;
    this->minute = inputMinute;
}

Date::~Date()
{
    //dtor
}
// 获取 天
int Date::getDay() {
    return this->day;
}
// 设置 天
void Date::setDay(int day) {
    this->day = day;
}
// 获取 年
int Date::getYear() {
    return this->year;
}
// 设置 年
void Date::setYear(int year) {
    this->year = year;
}
// 获取 月份
int Date::getMonth() {
    return this->month;
}
// 设置 月份
void Date::setMonth(int month) {
    this->month = month;
}
// 获取 小时
int Date::getHour() {
    return this->hour;
}
// 设置 小时
void Date::setHour(int hour) {
    this->hour = hour;
}
// 获取 分钟
int Date::getMinute() {
    return this->minute;
}
// 设置 分钟
void Date::setMinute(int minute) {
    this->minute += minute;
}
// 获取 日期
string Date::getDate() {
    string yearStr = to_string(this->year);
    string monthStr = to_string(this->month);
    string dayStr = to_string(this->day);
    if (this->month < 10)  monthStr = "0" + monthStr;
    if (this->day < 10)    dayStr = "0" + dayStr;
    return yearStr + "-" + monthStr + "-" + dayStr;
}
// 获取 时间
string Date::getTime() {
    string hourStr = to_string(this->hour);
    string minuteStr = to_string(this->minute);
    if (this->hour < 10)    hourStr = "0" + hourStr;
    if (this->minute < 10)  minuteStr = "0" + minuteStr;
    return hourStr + ":" + minuteStr;
}
// 重载 + 
Date& Date::operator+(int addMinute) {
    this->hour += (this->minute + addMinute) / 60;
    this->minute = (this->minute + addMinute) % 60;
    return *this;
}
// 重载 - 
Date& Date::operator-(int minusMinute) {
    if (this->minute - minusMinute >= 0) {
        this->hour += (this->minute - minusMinute) / 60;
        this->minute = (this->minute - minusMinute) % 60;
    }
    else {
        this->hour += (this->minute - minusMinute) / 60 - 1;
        this->minute = (this->minute - minusMinute) % 60 + 60;
    }
    return *this;
}